var app = getApp();
var c = require('../common.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var content=options.content;
    this.setData({ content: content});
    var that = this;
    wx.getStorage({
      key: 'arrayr',
      success: function (res) {
        var searcharrays = res.data;
        that.setData({
          searcharrays: searcharrays
        });
      },
      fail: function (res) { },
      complete: function (res) { },
    })

    var filePath = app.filePath;
    c.ajax(
      app.url + 'search',
      { content: content },
      res => {
        console.log(res);
        var arr= res.data;
        console.log(arr);
        this.setData({ arr: arr, filePath: filePath})
      }
    )
  },
  searchchanle: function (e) {
    var valueinfo = e.detail.value;
    this.setData({
      valueinfo: valueinfo
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  searchinfo: function (e) {
    var value = this.data.valueinfo;
    var searcharrays = this.data.searcharrays;
    if (searcharrays == undefined || searcharrays == '') {
      searcharrays = [];
    }
    searcharrays.push(value);
    wx.setStorage({
      key: 'arrayr',
      data: searcharrays,
    })
    this.setData({
      searcharrays: searcharrays
    })
    wx.navigateTo({
      url: '/pages/searchlist/searchlist?content=' + value
    }) 
  },
  searchchanle: function (e) {
    var valueinfo = e.detail.value;
    this.setData({
      valueinfo: valueinfo
    })
  },
  clickinfo:function(e){
    var gid=e.currentTarget.dataset.id;
    
  },
  inDetail: function (e) {
    // 商品类型：
    // 1 -> 一对一直播
    // 2 -> 单节视频
    // 3 -> 套课
    // 4 -> 套课中的视频
    // 5 -> 预约直播
    // 6 -> 一对多直播
    var gid = e.currentTarget.dataset.goodsid;
    var sql = 'w(goods_id=' + gid + ')f(type)l(1)';
    c.ajax(
      app.dbs + 'goods',
      { sql: sql },
      res => {
        var typeinfo = res.data.type;
        console.log(typeinfo);
        if (typeinfo == 2) {
          wx.navigateTo({
            url: '/pages/detailsdanke/detailsdanke?goods_id=' + gid,
          })
        } else if (typeinfo == 3) {
          wx.navigateTo({
            url: '/pages/detailtaoke/detailtaoke?goods_id=' + gid,
          })
        } else if (typeinfo == 1 || typeinfo == 6) {
          wx.navigateTo({
            url: '/pages/detailzhibo/detailzhibo?goods_id=' + gid,
          })
        }
      }
    )
  },
  more:function(){
    // <navigator url='/pages/searchmore/searchmore?content={{content}}' >
    var content = this.data.content;
    wx.navigateTo({
      url: '/pages/searchmore/searchmore?content=' + content,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  }
})